package com.chengqj;

import com.chengqj.dao.UserDO;
import com.chengqj.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Copyright © 2020年 com.qxkj. All rights reserved.
 *
 * @author chengqj
 * Transactional默认只会回滚RuntimeException类型异常
 * 非RuntimeException异常需要设置rollbackFor参数
 * version 1.0.0 (接口必须带上)
 * @date 2020/11/5 16:43
 */
@Service
public class UserServiceNoRollbackFor {
    @Autowired
    private UserRepository userRepository;

    /**
     * Transactional默认只会回滚RuntimeException类型异常
     * 非RuntimeException异常需要设置rollbackFor参数
     * @param userDO
     * @return
     */
    @Transactional
    public UserDO createRollbackForException(UserDO userDO) throws JpaException {
        userRepository.save(userDO);
        throw new JpaException();
    }



}
